package gui;

import application.CouleurTank;
import application.FrequenceFormes;
import application.JTextFieldLimit;
import application.PowerUp;
import application.PupListRenderer;
import application.Resolution;
import application.StatutJeu;
import application.StatutLabel;
import application.TankCouleurListRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;

/**
 *
 * @author Usager
 */
public class Jeu extends JPanel {

    private final double RATIO_INTERFACE = 0.15625;
    public Fenetre fenetre;
    private Jeu jeu;
    private Monde monde;
    private Thread threadJeu;
    private Resolution resolution;
    private StatutJeu statutJeu;
    private BoutonMenu btnNouvellePartie;
    private BoutonMenu btnOptions;
    private BoutonMenu btnQuitter;
    private BoutonMenu btnQuitterOui;
    private BoutonMenu btnRetourMenu;
    private BoutonMenu btnRetourJeu;
    private BoutonMenu btnNbJoueurs2;
    private BoutonMenu btnNbJoueurs3;
    private BoutonMenu btnNbJoueurs4;
    private BoutonMenu btnConfirmerNoms;
    private BoutonMenu btnConfirmerOptionsPartie;
    private BoutonMenu btnPasserTour;
    private JTextField txtJoueur1;
    private JTextField txtJoueur2;
    private JTextField txtJoueur3;
    private JTextField txtJoueur4;
    private LabelInterface lblInterfaceNom;
    private LabelInterface lblVie;
    private LabelInterface lblEssence;
    private LabelInterface lblAmmo;
    private JLabel lblTete;
    private JLabel lblOptionsViesTanks;
    private JLabel lblOptionsFuelTanks;
    private JLabel lblOptionsAmmoTanks;
    private JLabel lblOptionsDureeTour;
    private JLabel lblOptionsFrequenceFormes;
    private JComboBox<Resolution> cmbResolution;
    private JComboBox<CouleurTank> cmbCouleurTank1;
    private JComboBox<CouleurTank> cmbCouleurTank2;
    private JComboBox<CouleurTank> cmbCouleurTank3;
    private JComboBox<CouleurTank> cmbCouleurTank4;
    private JComboBox<PowerUp> cmbPowerUp1;
    private JComboBox<PowerUp> cmbPowerUp2;
    private JComboBox<PowerUp> cmbPowerUp3;
    private JComboBox<PowerUp> cmbPowerUp4;
    private JComboBox<Integer> cmbVieTanks;
    private JComboBox<Integer> cmbFuelTanks;
    private JComboBox<Integer> cmbAmmoTanks;
    private JComboBox<Integer> cmbDureeTours;
    private JComboBox<FrequenceFormes> cmbFrequenceFormes;
    private Image imgFondInterface;
    private Map<CouleurTank, Icon> iconesCouleursTanks;
    private Map<PowerUp, Icon> iconesPUP;
    private Map<PowerUp, Icon> iconesPUP600;
    private String[] nomsJoueurs;
    private boolean partiePause;

    public Jeu(Fenetre fenetre, Resolution resFenetre) {
        this.fenetre = fenetre;
        resolution = resFenetre;

        setSize(fenetre.getWidth(), fenetre.getHeight());
        jeu = this;
        monde = new Monde(jeu, resolution);
        iniThread();

        setLayout(null);

        setLocation(0, 0);

        loadImages();
        initialisation();
        setKeyBindings();

        startThread();
        setupJeu();
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        if (statutJeu == StatutJeu.PARTIE_EN_COURS) {
            g.drawImage(imgFondInterface, 0, 0, this);
        }
    }

    public void setResolution(Resolution resolution) {
        this.resolution = resolution;
    }

    private void setKeyBindings() {
        Action actionEsc = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (jeu.statutJeu == StatutJeu.MENU_PRINCIPAL) {
                    statutJeu = StatutJeu.CONFIRMATION_QUITTER;
                    setupJeu();
                } else if (jeu.statutJeu == StatutJeu.PARTIE_EN_COURS) {
                    statutJeu = StatutJeu.PARTIE_PAUSE;
                    setupJeu();
                } else if (jeu.statutJeu == StatutJeu.PARTIE_PAUSE) {
                    statutJeu = StatutJeu.PARTIE_EN_COURS;
                    setupJeu();
                } else if (jeu.statutJeu == StatutJeu.OPTIONS || jeu.statutJeu == StatutJeu.SELECTION_NOMBRE_JOUEURS) {
                    statutJeu = StatutJeu.MENU_PRINCIPAL;
                    setupJeu();
                } else if (jeu.statutJeu == StatutJeu.SELECTION_NOMS_JOUEURS) {
                    statutJeu = StatutJeu.SELECTION_NOMBRE_JOUEURS;
                    setupJeu();
                } else if (jeu.statutJeu == StatutJeu.OPTIONS_PARTIE) {
                    statutJeu = StatutJeu.SELECTION_NOMS_JOUEURS;
                    setupJeu();
                }
            }
        };

        getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "actionEscape");
        getActionMap().put("actionEscape", actionEsc);
    }

    private void loadImages() {
        iconesPUP = new HashMap<>();
        iconesPUP.put(PowerUp.PLUS_DE_VIE, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Vie.png"))));
        iconesPUP.put(PowerUp.PLUS_DE_DMG, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Dmg.png"))));
        iconesPUP.put(PowerUp.PLUS_DE_RAM, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Ram.png"))));
        iconesPUP.put(PowerUp.PLUS_DE_PROJECTILES, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Ammo.png"))));
        iconesPUP.put(PowerUp.PLUS_DE_FUEL, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Fuel.png"))));

        iconesPUP600 = new HashMap<>();
        iconesPUP600.put(PowerUp.PLUS_DE_VIE, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Vie_600.png"))));
        iconesPUP600.put(PowerUp.PLUS_DE_DMG, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Dmg_600.png"))));
        iconesPUP600.put(PowerUp.PLUS_DE_RAM, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Ram_600.png"))));
        iconesPUP600.put(PowerUp.PLUS_DE_PROJECTILES, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Ammo_600.png"))));
        iconesPUP600.put(PowerUp.PLUS_DE_FUEL, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/PUP_Fuel_600.png"))));

        iconesCouleursTanks = new HashMap<>();
        iconesCouleursTanks.put(CouleurTank.VERT, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Tank_Vert_Demo.png"))));
        iconesCouleursTanks.put(CouleurTank.BLEU, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Tank_Bleu_Demo.png"))));
        iconesCouleursTanks.put(CouleurTank.JAUNE, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Tank_Jaune_Demo.png"))));
        iconesCouleursTanks.put(CouleurTank.ROUGE, new ImageIcon(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Tank_Rouge_Demo.png"))));
    }

    /**
     * Initialisation de la classe Jeu
     */
    private void initialisation() {
        statutJeu = StatutJeu.MENU_PRINCIPAL;
        partiePause = false;
        nomsJoueurs = new String[4];
        setCurseur();

        //Bouton nouvelle partie
        btnNouvellePartie = new BoutonMenu("Nouvelle partie", resolution);
        btnNouvellePartie.setSize(getWidth() / 4, getHeight() / 8);
        btnNouvellePartie.setLocation(getWidth() / 2 - btnNouvellePartie.getWidth() / 2, getHeight() / 3 - btnNouvellePartie.getHeight() / 2);
        btnNouvellePartie.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statutJeu = StatutJeu.SELECTION_NOMBRE_JOUEURS;
                setupJeu();
            }
        });

        //Bouton permettant d'acceder aux options
        btnOptions = new BoutonMenu("Options", resolution);
        btnOptions.setSize(getWidth() / 4, getHeight() / 8);
        btnOptions.setLocation(getWidth() / 2 - btnOptions.getWidth() / 2, getHeight() / 2 - btnOptions.getHeight() / 2);
        btnOptions.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statutJeu = StatutJeu.OPTIONS;
                setupJeu();
            }
        });

        //Bouton quitter le jeu
        btnQuitter = new BoutonMenu("Quitter", resolution);
        btnQuitter.setSize(getWidth() / 4, getHeight() / 8);
        btnQuitter.setLocation(getWidth() / 2 - btnQuitter.getWidth() / 2, 2 * getHeight() / 3 - btnQuitter.getHeight() / 2);
        btnQuitter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statutJeu = StatutJeu.CONFIRMATION_QUITTER;
                setupJeu();
            }
        });

        //Bouton confirmer quitter oui
        btnQuitterOui = new BoutonMenu("OUI", resolution);
        btnQuitterOui.setSize(getWidth() / 4, getHeight() / 8);
        btnQuitterOui.setLocation(getWidth() / 2 - btnQuitterOui.getWidth() / 2, 2 * getHeight() / 3 - btnQuitterOui.getHeight() / 2);
        btnQuitterOui.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        //Bouton de retour au menu (utilise dans plusieurs situations)
        btnRetourMenu = new BoutonMenu("", resolution);
        btnRetourMenu.setSize(getWidth() / 4, getHeight() / 8);
        btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, getHeight() / 3 - btnRetourMenu.getHeight() / 2);
        btnRetourMenu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (statutJeu == StatutJeu.PARTIE_PAUSE) {
                    statutJeu = StatutJeu.MENU_PRINCIPAL;
                    setupJeu();

                    monde = new Monde(jeu, resolution);
                } else if (statutJeu == StatutJeu.OPTIONS && !partiePause) {
                    Resolution resolutionInitiale = resolution;

                    fenetre.setResolution((Resolution) cmbResolution.getSelectedItem());
                    setResolution((Resolution) cmbResolution.getSelectedItem());

                    fenetre.refresh(resolutionInitiale);

                    statutJeu = StatutJeu.MENU_PRINCIPAL;
                    setupJeu();
                } else if (statutJeu == StatutJeu.OPTIONS && partiePause) {
                    Resolution resolutionInitiale = resolution;

                    fenetre.setResolution((Resolution) cmbResolution.getSelectedItem());
                    setResolution((Resolution) cmbResolution.getSelectedItem());

                    fenetre.refresh(resolutionInitiale);

                    statutJeu = StatutJeu.PARTIE_PAUSE;
                    setupJeu();
                } else if (statutJeu == StatutJeu.OPTIONS_PARTIE) {
                    statutJeu = StatutJeu.SELECTION_NOMS_JOUEURS;
                    setupJeu();
                } else if (statutJeu == StatutJeu.SELECTION_NOMS_JOUEURS) {
                    statutJeu = StatutJeu.SELECTION_NOMBRE_JOUEURS;
                    setupJeu();
                } else if (statutJeu == StatutJeu.SELECTION_NOMBRE_JOUEURS) {
                    statutJeu = StatutJeu.MENU_PRINCIPAL;
                    setupJeu();
                }
            }
        });

        //Bouton de retour au jeu
        btnRetourJeu = new BoutonMenu("Retour", resolution);
        btnRetourJeu.setSize(getWidth() / 4, getHeight() / 8);
        btnRetourJeu.setLocation(getWidth() / 2 - btnRetourJeu.getWidth() / 2, getHeight() / 3 - btnRetourJeu.getHeight() / 2);
        btnRetourJeu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statutJeu = StatutJeu.PARTIE_EN_COURS;
                setupJeu();
            }
        });

        //Bouton qui selectionne une partie a 2 joueurs
        btnNbJoueurs2 = new BoutonMenu("2", resolution);
        btnNbJoueurs2.setSize(getWidth() / 4, getHeight() / 8);
        btnNbJoueurs2.setLocation(getWidth() / 2 - btnNbJoueurs2.getWidth() / 2, getHeight() / 3 - btnNbJoueurs2.getHeight() / 2);
        btnNbJoueurs2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                monde.setNombreJoueurs(2);

                statutJeu = StatutJeu.SELECTION_NOMS_JOUEURS;
                setupJeu();
            }
        });

        //Bouton qui selectionne une partie a 3 joueurs
        btnNbJoueurs3 = new BoutonMenu("3", resolution);
        btnNbJoueurs3.setSize(getWidth() / 4, getHeight() / 8);
        btnNbJoueurs3.setLocation(getWidth() / 2 - btnNbJoueurs3.getWidth() / 2, getHeight() / 2 - btnNbJoueurs3.getHeight() / 2);
        btnNbJoueurs3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                monde.setNombreJoueurs(3);

                statutJeu = StatutJeu.SELECTION_NOMS_JOUEURS;
                setupJeu();
            }
        });

        //Bouton qui selectionne une partie a 4 joueurs
        btnNbJoueurs4 = new BoutonMenu("4", resolution);
        btnNbJoueurs4.setSize(getWidth() / 4, getHeight() / 8);
        btnNbJoueurs4.setLocation(getWidth() / 2 - btnNbJoueurs4.getWidth() / 2, 2 * getHeight() / 3 - btnNbJoueurs4.getHeight() / 2);
        btnNbJoueurs4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                monde.setNombreJoueurs(4);

                statutJeu = StatutJeu.SELECTION_NOMS_JOUEURS;
                setupJeu();
            }
        });

        //Bouton qui confirme les noms des joueurs
        btnConfirmerNoms = new BoutonMenu("OK", resolution);
        btnConfirmerNoms.setSize(getWidth() / 4, getHeight() / 8);
        btnConfirmerNoms.setLocation(getWidth() / 2 - btnConfirmerNoms.getWidth() / 2, 4 * getHeight() / 6 - btnConfirmerNoms.getHeight() / 2);
        btnConfirmerNoms.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                nomsJoueurs[0] = txtJoueur1.getText();
                nomsJoueurs[1] = txtJoueur2.getText();
                nomsJoueurs[2] = txtJoueur3.getText();
                nomsJoueurs[3] = txtJoueur4.getText();

                statutJeu = StatutJeu.OPTIONS_PARTIE;
                setupJeu();
            }
        });

        //Bouton qui confirme les options de partie
        btnConfirmerOptionsPartie = new BoutonMenu("OK", resolution);
        btnConfirmerOptionsPartie.setSize(getWidth() / 4, getHeight() / 8);
        btnConfirmerOptionsPartie.setLocation(getWidth() / 2 - btnConfirmerOptionsPartie.getWidth() / 2, 17 * getHeight() / 24 - btnConfirmerOptionsPartie.getHeight() / 2);
        btnConfirmerOptionsPartie.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statutJeu = StatutJeu.PARTIE_EN_COURS;
                monde.commencerLaPartie((int) jeu.cmbVieTanks.getSelectedItem(), (int) jeu.cmbFuelTanks.getSelectedItem(), (int) jeu.cmbAmmoTanks.getSelectedItem(), (FrequenceFormes) jeu.cmbFrequenceFormes.getSelectedItem());
                setupJeu();
            }
        });

        //Bouton qui passe le tour d'un joueur
        btnPasserTour = new BoutonMenu("Passer", resolution);
        btnPasserTour.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        btnPasserTour.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() - btnPasserTour.getHeight() - (int) (getWidth() * RATIO_INTERFACE) / 15);
        btnPasserTour.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                monde.changementDeTour();
            }
        });

        //Zone d'entree du nom du joueur 1
        txtJoueur1 = new JTextField();
        txtJoueur1.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur1.setLocation(getWidth() / 2 - txtJoueur1.getWidth() / 2, 7 * getHeight() / 24 - txtJoueur1.getHeight() / 2);
        if (resolution == Resolution.R1920x1080) {
            txtJoueur1.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            txtJoueur1.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            txtJoueur1.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        txtJoueur1.setHorizontalAlignment(JTextField.CENTER);
        txtJoueur1.setDocument(new JTextFieldLimit(10));
        txtJoueur1.setText("Joueur 1");

        //Zone d'entree du nom du joueur 2
        txtJoueur2 = new JTextField();
        txtJoueur2.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur2.setLocation(getWidth() / 2 - txtJoueur2.getWidth() / 2, 9 * getHeight() / 24 - txtJoueur2.getHeight() / 2);
        if (resolution == Resolution.R1920x1080) {
            txtJoueur2.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            txtJoueur2.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            txtJoueur2.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        txtJoueur2.setHorizontalAlignment(JTextField.CENTER);
        txtJoueur2.setDocument(new JTextFieldLimit(10));
        txtJoueur2.setText("Joueur 2");

        //Zone d'entree du nom du joueur 3
        txtJoueur3 = new JTextField();
        txtJoueur3.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur3.setLocation(getWidth() / 2 - txtJoueur3.getWidth() / 2, 11 * getHeight() / 24 - txtJoueur3.getHeight() / 2);
        if (resolution == Resolution.R1920x1080) {
            txtJoueur3.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            txtJoueur3.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            txtJoueur3.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        txtJoueur3.setHorizontalAlignment(JTextField.CENTER);
        txtJoueur3.setDocument(new JTextFieldLimit(10));
        txtJoueur3.setText("Joueur 3");

        //Zone d'entree du nom du joueur 4
        txtJoueur4 = new JTextField();
        txtJoueur4.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur4.setLocation(getWidth() / 2 - txtJoueur4.getWidth() / 2, 13 * getHeight() / 24 - txtJoueur4.getHeight() / 2);
        if (resolution == Resolution.R1920x1080) {
            txtJoueur4.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            txtJoueur4.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            txtJoueur4.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        txtJoueur4.setHorizontalAlignment(JTextField.CENTER);
        txtJoueur4.setDocument(new JTextFieldLimit(10));
        txtJoueur4.setText("Joueur 4");
        
        //Etiquette nom joueur
        lblInterfaceNom = new LabelInterface(StatutLabel.NOM, resolution);
        lblInterfaceNom.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblInterfaceNom.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, (int) (getWidth() * RATIO_INTERFACE) / 15);
        lblInterfaceNom.setRatioRemplissage(0);

        //Etiquette de vie tank
        lblVie = new LabelInterface(StatutLabel.VIE, resolution);
        lblVie.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblVie.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, 2 * (int) (getWidth() * RATIO_INTERFACE) / 15 + lblVie.getHeight());

        //Etiquette d'essence tank
        lblEssence = new LabelInterface(StatutLabel.ESSENCE, resolution);
        lblEssence.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblEssence.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, 3 * (int) (getWidth() * RATIO_INTERFACE) / 15 + 2 * lblEssence.getHeight());
        
        //Etiquette d'ammo tank
        lblAmmo = new LabelInterface(StatutLabel.AMMO, resolution);
        lblAmmo.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblAmmo.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, 4 * (int) (getWidth() * RATIO_INTERFACE) / 15 + 3 * lblAmmo.getHeight());

        //Etiquette d'affichage des titres
        lblTete = new JLabel("TANKS", JLabel.CENTER);
        if (resolution == Resolution.R1920x1080) {
            lblTete.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 75));
        } else if (resolution == Resolution.R1280x1024) {
            lblTete.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 60));
        } else if (resolution == Resolution.R800x600) {
            lblTete.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 35));
        }
        lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
        lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
        lblTete.setBackground(Color.BLACK);
        lblTete.setForeground(Color.WHITE);

        //Etiquette vies des tanks
        lblOptionsViesTanks = new JLabel("Vie des tanks : ", JLabel.RIGHT);
        if (resolution == Resolution.R1920x1080) {
            lblOptionsViesTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            lblOptionsViesTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            lblOptionsViesTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        lblOptionsViesTanks.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsViesTanks.setLocation(getWidth() / 2 - lblOptionsViesTanks.getWidth(), 6 * getHeight() / 24 - lblOptionsViesTanks.getHeight() / 2);
        lblOptionsViesTanks.setBackground(Color.BLACK);
        lblOptionsViesTanks.setForeground(Color.WHITE);

        //Etiquette d'essence des tanks
        lblOptionsFuelTanks = new JLabel("Essence des tanks : ", JLabel.RIGHT);
        if (resolution == Resolution.R1920x1080) {
            lblOptionsFuelTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            lblOptionsFuelTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            lblOptionsFuelTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        lblOptionsFuelTanks.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsFuelTanks.setLocation(getWidth() / 2 - lblOptionsFuelTanks.getWidth(), 8 * getHeight() / 24 - lblOptionsFuelTanks.getHeight() / 2);
        lblOptionsFuelTanks.setBackground(Color.BLACK);
        lblOptionsFuelTanks.setForeground(Color.WHITE);

        //Etiquette d'ammo des tanks
        lblOptionsAmmoTanks = new JLabel("Balles des tanks : ", JLabel.RIGHT);
        if (resolution == Resolution.R1920x1080) {
            lblOptionsAmmoTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            lblOptionsAmmoTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            lblOptionsAmmoTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        lblOptionsAmmoTanks.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsAmmoTanks.setLocation(getWidth() / 2 - lblOptionsAmmoTanks.getWidth(), 10 * getHeight() / 24 - lblOptionsAmmoTanks.getHeight() / 2);
        lblOptionsAmmoTanks.setBackground(Color.BLACK);
        lblOptionsAmmoTanks.setForeground(Color.WHITE);

        //Etiquette de duree des tours
        lblOptionsDureeTour = new JLabel("Duree des tours : ", JLabel.RIGHT);
        if (resolution == Resolution.R1920x1080) {
            lblOptionsDureeTour.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            lblOptionsDureeTour.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            lblOptionsDureeTour.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        lblOptionsDureeTour.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsDureeTour.setLocation(getWidth() / 2 - lblOptionsDureeTour.getWidth(), 12 * getHeight() / 24 - lblOptionsDureeTour.getHeight() / 2);
        lblOptionsDureeTour.setBackground(Color.BLACK);
        lblOptionsDureeTour.setForeground(Color.WHITE);

        //Etiquette de frequence des obstacles
        lblOptionsFrequenceFormes = new JLabel("Nombre d'obstacles : ", JLabel.RIGHT);
        if (resolution == Resolution.R1920x1080) {
            lblOptionsFrequenceFormes.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            lblOptionsFrequenceFormes.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            lblOptionsFrequenceFormes.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }
        lblOptionsFrequenceFormes.setSize(2 * getWidth() / 8, getHeight() / 16);
        lblOptionsFrequenceFormes.setLocation(getWidth() / 2 - lblOptionsFrequenceFormes.getWidth(), 14 * getHeight() / 24 - lblOptionsFrequenceFormes.getHeight() / 2);
        lblOptionsFrequenceFormes.setBackground(Color.BLACK);
        lblOptionsFrequenceFormes.setForeground(Color.WHITE);

        //Combobox permettant de selectionner la resolution du programme
        Resolution[] tableauResolutions = {Resolution.R1920x1080, Resolution.R1280x1024, Resolution.R800x600};
        cmbResolution = new JComboBox<>(tableauResolutions);
        cmbResolution.setSize(getWidth() / 4, getHeight() / 16);
        cmbResolution.setLocation(getWidth() / 2 - cmbResolution.getWidth() / 2, getHeight() / 2 - cmbResolution.getHeight() / 2);
        cmbResolution.setSelectedItem(resolution);

        //Combobox de selection de la couleur du tank joueur 1
        CouleurTank[] tableauCouleurTank = {CouleurTank.VERT, CouleurTank.BLEU, CouleurTank.JAUNE, CouleurTank.ROUGE};
        cmbCouleurTank1 = new JComboBox<>(tableauCouleurTank);
        cmbCouleurTank1.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank1.setLocation(txtJoueur1.getX() - cmbCouleurTank1.getWidth() - 10, 7 * getHeight() / 24 - cmbCouleurTank1.getHeight() / 2);
        cmbCouleurTank1.setSelectedIndex(0);

        //Combobox de selection de la couleur du tank joueur 2
        cmbCouleurTank2 = new JComboBox<>(tableauCouleurTank);
        cmbCouleurTank2.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank2.setLocation(txtJoueur2.getX() - cmbCouleurTank2.getWidth() - 10, 9 * getHeight() / 24 - cmbCouleurTank2.getHeight() / 2);
        cmbCouleurTank2.setSelectedIndex(0);

        //Combobox de selection de la couleur du tank joueur 3
        cmbCouleurTank3 = new JComboBox<>(tableauCouleurTank);
        cmbCouleurTank3.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank3.setLocation(txtJoueur3.getX() - cmbCouleurTank3.getWidth() - 10, 11 * getHeight() / 24 - cmbCouleurTank3.getHeight() / 2);
        cmbCouleurTank3.setSelectedIndex(0);

        //Combobox de selection de la couleur du tank joueur 4
        cmbCouleurTank4 = new JComboBox<>(tableauCouleurTank);
        cmbCouleurTank4.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank4.setLocation(txtJoueur4.getX() - cmbCouleurTank4.getWidth() - 10, 13 * getHeight() / 24 - cmbCouleurTank4.getHeight() / 2);
        cmbCouleurTank4.setSelectedIndex(0);

        //Combobox de selection du powerup joueur 1
        PowerUp[] tableauPowerUps = {PowerUp.PLUS_DE_VIE, PowerUp.PLUS_DE_DMG, PowerUp.PLUS_DE_RAM, PowerUp.PLUS_DE_PROJECTILES, PowerUp.PLUS_DE_FUEL};
        cmbPowerUp1 = new JComboBox<>(tableauPowerUps);
        cmbPowerUp1.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp1.setLocation(txtJoueur1.getX() + txtJoueur1.getWidth() + 10, 7 * getHeight() / 24 - cmbPowerUp1.getHeight() / 2);
        cmbPowerUp1.setSelectedIndex(0);

        //Combobox de selection du powerup joueur 2
        cmbPowerUp2 = new JComboBox<>(tableauPowerUps);
        cmbPowerUp2.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp2.setLocation(txtJoueur2.getX() + txtJoueur2.getWidth() + 10, 9 * getHeight() / 24 - cmbPowerUp2.getHeight() / 2);
        cmbPowerUp2.setSelectedIndex(0);

        //Combobox de selection du powerup joueur 3
        cmbPowerUp3 = new JComboBox<>(tableauPowerUps);
        cmbPowerUp3.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp3.setLocation(txtJoueur3.getX() + txtJoueur3.getWidth() + 10, 11 * getHeight() / 24 - cmbPowerUp3.getHeight() / 2);
        cmbPowerUp3.setSelectedIndex(0);

        //Combobox de selection du powerup joueur 4
        cmbPowerUp4 = new JComboBox<>(tableauPowerUps);
        cmbPowerUp4.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp4.setLocation(txtJoueur4.getX() + txtJoueur4.getWidth() + 10, 13 * getHeight() / 24 - cmbPowerUp4.getHeight() / 2);
        cmbPowerUp4.setSelectedIndex(0);

        //Combobox de selection de la vie des tanks
        Integer[] tableauVies = {5, 10, 15, 25, 50};
        cmbVieTanks = new JComboBox<>(tableauVies);
        cmbVieTanks.setSize(getWidth() / 9, getHeight() / 16);
        cmbVieTanks.setLocation(getWidth() / 2, 6 * getHeight() / 24 - cmbVieTanks.getHeight() / 2);
        cmbVieTanks.setSelectedIndex(1);

        //Combobox de selection de l'essence des tanks
        Integer[] tableauFuel = {250, 500, 750, 1000, 1500};
        cmbFuelTanks = new JComboBox<>(tableauFuel);
        cmbFuelTanks.setSize(getWidth() / 9, getHeight() / 16);
        cmbFuelTanks.setLocation(getWidth() / 2, 8 * getHeight() / 24 - cmbFuelTanks.getHeight() / 2);
        cmbFuelTanks.setSelectedIndex(2);

        //Combobox de selection du nombre de balles des tanks
        Integer[] tableauAmmo = {1, 2, 3, 4, 5};
        cmbAmmoTanks = new JComboBox<>(tableauAmmo);
        cmbAmmoTanks.setSize(getWidth() / 9, getHeight() / 16);
        cmbAmmoTanks.setLocation(getWidth() / 2, 10 * getHeight() / 24 - cmbAmmoTanks.getHeight() / 2);
        cmbAmmoTanks.setSelectedIndex(0);

        //Combobox de selection de la duree d'un tour
        Integer[] tableauDuree = {10, 20, 30, 45, 60, 120};
        cmbDureeTours = new JComboBox<>(tableauDuree);
        cmbDureeTours.setSize(getWidth() / 9, getHeight() / 16);
        cmbDureeTours.setLocation(getWidth() / 2, 12 * getHeight() / 24 - cmbDureeTours.getHeight() / 2);
        cmbDureeTours.setSelectedIndex(2);

        //Combobox de selection de la frequences d'apparition des obstacles
        FrequenceFormes[] tableauFrequences = {FrequenceFormes.VIDE, FrequenceFormes.LEGER, FrequenceFormes.MODERE, FrequenceFormes.BEAUCOUP, FrequenceFormes.ABUSIF};
        cmbFrequenceFormes = new JComboBox<>(tableauFrequences);
        cmbFrequenceFormes.setSize(getWidth() / 9, getHeight() / 16);
        cmbFrequenceFormes.setLocation(getWidth() / 2, 14 * getHeight() / 24 - cmbFrequenceFormes.getHeight() / 2);
        cmbFrequenceFormes.setSelectedIndex(1);

        //Initialisation de l'image de fond de l'interface de partie
        if (resolution == Resolution.R1920x1080) {
            imgFondInterface = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Fond_Interface_1080.png"));
        } else if (resolution == Resolution.R1280x1024) {
            imgFondInterface = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Fond_Interface_1024.png"));
        } else if (resolution == Resolution.R800x600) {
            imgFondInterface = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Fond_Interface_600.png"));
        }

        //Initialisation des renderers des comboboxes
        if (resolution == Resolution.R1920x1080 || resolution == Resolution.R1280x1024) {
            cmbPowerUp1.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp2.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp3.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp4.setRenderer(new PupListRenderer(iconesPUP));

            cmbCouleurTank1.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
            cmbCouleurTank2.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
            cmbCouleurTank3.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
            cmbCouleurTank4.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
        } else if (resolution == Resolution.R800x600) {
            cmbPowerUp1.setRenderer(new PupListRenderer(iconesPUP600));
            cmbPowerUp2.setRenderer(new PupListRenderer(iconesPUP600));
            cmbPowerUp3.setRenderer(new PupListRenderer(iconesPUP600));
            cmbPowerUp4.setRenderer(new PupListRenderer(iconesPUP600));

            cmbCouleurTank1.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
            cmbCouleurTank2.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
            cmbCouleurTank3.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
            cmbCouleurTank4.setRenderer(new TankCouleurListRenderer(iconesCouleursTanks));
        }
    }

    /**
     * Configure le curseur pour le rendre invisible
     */
    private void setCurseur() {
        Cursor curseur;
        Image imageCurseur = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Curseur.png"));
        Point pointCurseur = new Point(11, 0);
        curseur = Toolkit.getDefaultToolkit().createCustomCursor(imageCurseur, pointCurseur, "Curseur");

        setCursor(curseur);
    }

    /**
     * Initialisation du Thread principal
     */
    private void iniThread() {
        threadJeu = new Thread() {
            @Override
            public synchronized void run() {


                while (true) {

                    monde.mAJMonde();
                    setupEtiquettesInterface();
                    repaint();
                    revalidate();

                    try {
                        Thread.sleep(20);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                        System.exit(1);
                    }



                }
            }
        };
    }

    /**
     * Demarrage du Thread principal
     */
    private void startThread() {
        threadJeu.start();

    }

    public void setupJeu() {
        if (statutJeu == StatutJeu.MENU_PRINCIPAL) {
            partiePause = false;

            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("TANKS");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);

            add(btnNouvellePartie);
            add(btnOptions);
            add(btnQuitter);
            add(lblTete);

            btnNouvellePartie.setNeutre();
            btnOptions.setNeutre();
            btnQuitter.setNeutre();
        } else if (statutJeu == StatutJeu.OPTIONS) {
            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("OPTIONS");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
            btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, 5 * getHeight() / 6 - btnRetourMenu.getHeight() / 2);
            btnRetourMenu.setText("OK");

            add(cmbResolution);
            add(btnRetourMenu);
            add(lblTete);

            btnRetourMenu.setNeutre();
        } else if (statutJeu == StatutJeu.SELECTION_NOMBRE_JOUEURS) {
            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("NOMBRE DE JOUEURS");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
            btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, 5 * getHeight() / 6 - btnRetourMenu.getHeight() / 2);
            btnRetourMenu.setText("RETOUR");

            add(btnNbJoueurs2);
            add(btnNbJoueurs3);
            add(btnNbJoueurs4);
            add(btnRetourMenu);
            add(lblTete);

            btnNbJoueurs2.setNeutre();
            btnNbJoueurs3.setNeutre();
            btnNbJoueurs4.setNeutre();
            btnRetourMenu.setNeutre();
        } else if (statutJeu == StatutJeu.SELECTION_NOMS_JOUEURS) {
            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("NOMS DES JOUEURS");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
            btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, 5 * getHeight() / 6 - btnRetourMenu.getHeight() / 2);
            btnRetourMenu.setText("RETOUR");

            switch (monde.getNombreJoueurs()) {
                case 2: {
                    add(txtJoueur1);
                    add(txtJoueur2);

                    add(cmbCouleurTank1);
                    add(cmbCouleurTank2);

                    add(cmbPowerUp1);
                    add(cmbPowerUp2);
                }
                break;

                case 3: {
                    add(txtJoueur1);
                    add(txtJoueur2);
                    add(txtJoueur3);

                    add(cmbCouleurTank1);
                    add(cmbCouleurTank2);
                    add(cmbCouleurTank3);

                    add(cmbPowerUp1);
                    add(cmbPowerUp2);
                    add(cmbPowerUp3);
                }
                break;

                case 4: {
                    add(txtJoueur1);
                    add(txtJoueur2);
                    add(txtJoueur3);
                    add(txtJoueur4);

                    add(cmbCouleurTank1);
                    add(cmbCouleurTank2);
                    add(cmbCouleurTank3);
                    add(cmbCouleurTank4);

                    add(cmbPowerUp1);
                    add(cmbPowerUp2);
                    add(cmbPowerUp3);
                    add(cmbPowerUp4);
                }
                break;
            }

            add(btnConfirmerNoms);
            add(btnRetourMenu);
            add(lblTete);

            btnConfirmerNoms.setNeutre();
        } else if (statutJeu == StatutJeu.OPTIONS_PARTIE) {
            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("OPTIONS DE PARTIE");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
            btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, 21 * getHeight() / 24 - btnRetourMenu.getHeight() / 2);
            btnRetourMenu.setText("RETOUR");

            add(lblOptionsViesTanks);
            add(lblOptionsFuelTanks);
            add(lblOptionsAmmoTanks);
            add(lblOptionsDureeTour);
            add(lblOptionsFrequenceFormes);
            add(cmbVieTanks);
            add(cmbFuelTanks);
            add(cmbAmmoTanks);
            add(cmbDureeTours);
            add(cmbFrequenceFormes);
            add(btnConfirmerOptionsPartie);
            add(btnRetourMenu);
            add(lblTete);

            btnConfirmerOptionsPartie.setNeutre();
            btnRetourMenu.setNeutre();
        } else if (statutJeu == StatutJeu.PARTIE_PAUSE) {
            partiePause = true;

            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("PAUSE");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
            btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, 2 * getHeight() / 3 - btnRetourMenu.getHeight() / 2);
            btnRetourMenu.setText("Fin de partie");

            add(btnRetourJeu);
            add(btnOptions);
            add(btnRetourMenu);
            add(lblTete);

            btnRetourJeu.setNeutre();
            btnOptions.setNeutre();
            btnRetourMenu.setNeutre();
        } else if (statutJeu == StatutJeu.CONFIRMATION_QUITTER) {
            removeAll();
            setBackground(Color.BLACK);

            lblTete.setText("Voulez-vous vraiment quitter?");
            lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
            lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
            btnRetourMenu.setLocation(getWidth() / 2 - btnRetourMenu.getWidth() / 2, getHeight() / 3 - btnRetourMenu.getHeight() / 2);
            btnRetourMenu.setText("NON");

            add(btnQuitterOui);
            add(btnRetourMenu);
            add(lblTete);

            btnQuitterOui.setNeutre();
            btnRetourMenu.setNeutre();
        } else if (statutJeu == StatutJeu.PARTIE_EN_COURS) {
            partiePause = false;

            removeAll();

            add(lblInterfaceNom);
            add(lblVie);
            add(lblEssence);
            add(lblAmmo);
            add(btnPasserTour);
            
            add(monde);

            btnPasserTour.setNeutre();
        }
    }

    public void setStatutJeu(StatutJeu statutJeu) {
        this.statutJeu = statutJeu;
    }

    public void refresh(Resolution resolutionInitiale) {
        setSize(resolution.getLargeur(), resolution.getHauteur());

        if (resolution == Resolution.R1920x1080) {
            lblTete.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 75));
            txtJoueur1.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            txtJoueur2.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            txtJoueur3.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            txtJoueur4.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            lblOptionsViesTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            lblOptionsFuelTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            lblOptionsAmmoTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            lblOptionsDureeTour.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            lblOptionsFrequenceFormes.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
            lblInterfaceNom.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 45));
        } else if (resolution == Resolution.R1280x1024) {
            lblTete.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 60));
            txtJoueur1.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            txtJoueur2.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            txtJoueur3.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            txtJoueur4.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            lblOptionsViesTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            lblOptionsFuelTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            lblOptionsAmmoTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            lblOptionsDureeTour.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            lblOptionsFrequenceFormes.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
            lblInterfaceNom.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 30));
        } else if (resolution == Resolution.R800x600) {
            lblTete.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 35));
            txtJoueur1.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            txtJoueur2.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            txtJoueur3.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            txtJoueur4.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            lblOptionsViesTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            lblOptionsFuelTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            lblOptionsAmmoTanks.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            lblOptionsDureeTour.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            lblOptionsFrequenceFormes.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
            lblInterfaceNom.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20));
        }

        btnNouvellePartie.setSize(getWidth() / 4, getHeight() / 8);
        btnNouvellePartie.setLocation(getWidth() / 2 - btnNouvellePartie.getWidth() / 2, getHeight() / 3 - btnNouvellePartie.getHeight() / 2);
        btnOptions.setSize(getWidth() / 4, getHeight() / 8);
        btnOptions.setLocation(getWidth() / 2 - btnOptions.getWidth() / 2, getHeight() / 2 - btnOptions.getHeight() / 2);
        btnQuitter.setSize(getWidth() / 4, getHeight() / 8);
        btnQuitter.setLocation(getWidth() / 2 - btnQuitter.getWidth() / 2, 2 * getHeight() / 3 - btnQuitter.getHeight() / 2);
        btnQuitterOui.setSize(getWidth() / 4, getHeight() / 8);
        btnQuitterOui.setLocation(getWidth() / 2 - btnQuitterOui.getWidth() / 2, 2 * getHeight() / 3 - btnQuitterOui.getHeight() / 2);
        btnRetourMenu.setSize(getWidth() / 4, getHeight() / 8);
        btnRetourMenu.setLocation(getWidth() / 2 - btnQuitterOui.getWidth() / 2, getHeight() / 3 - btnQuitterOui.getHeight() / 2);
        btnRetourJeu.setSize(getWidth() / 4, getHeight() / 8);
        btnRetourJeu.setLocation(getWidth() / 2 - btnRetourJeu.getWidth() / 2, getHeight() / 3 - btnRetourJeu.getHeight() / 2);
        btnNbJoueurs2.setSize(getWidth() / 4, getHeight() / 8);
        btnNbJoueurs2.setLocation(getWidth() / 2 - btnNbJoueurs2.getWidth() / 2, getHeight() / 3 - btnNbJoueurs2.getHeight() / 2);
        btnNbJoueurs3.setSize(getWidth() / 4, getHeight() / 8);
        btnNbJoueurs3.setLocation(getWidth() / 2 - btnNbJoueurs3.getWidth() / 2, getHeight() / 2 - btnNbJoueurs3.getHeight() / 2);
        btnNbJoueurs4.setSize(getWidth() / 4, getHeight() / 8);
        btnNbJoueurs4.setLocation(getWidth() / 2 - btnNbJoueurs4.getWidth() / 2, 2 * getHeight() / 3 - btnNbJoueurs4.getHeight() / 2);
        btnConfirmerNoms.setSize(getWidth() / 4, getHeight() / 8);
        btnConfirmerNoms.setLocation(getWidth() / 2 - btnConfirmerNoms.getWidth() / 2, 4 * getHeight() / 6 - btnConfirmerNoms.getHeight() / 2);
        btnConfirmerOptionsPartie.setSize(getWidth() / 4, getHeight() / 8);
        btnConfirmerOptionsPartie.setLocation(getWidth() / 2 - btnConfirmerOptionsPartie.getWidth() / 2, 17 * getHeight() / 24 - btnConfirmerOptionsPartie.getHeight() / 2);
        txtJoueur1.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur1.setLocation(getWidth() / 2 - txtJoueur1.getWidth() / 2, 7 * getHeight() / 24 - txtJoueur1.getHeight() / 2);
        txtJoueur2.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur2.setLocation(getWidth() / 2 - txtJoueur2.getWidth() / 2, 9 * getHeight() / 24 - txtJoueur2.getHeight() / 2);
        txtJoueur3.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur3.setLocation(getWidth() / 2 - txtJoueur3.getWidth() / 2, 11 * getHeight() / 24 - txtJoueur3.getHeight() / 2);
        txtJoueur4.setSize(getWidth() / 4, getHeight() / 16);
        txtJoueur4.setLocation(getWidth() / 2 - txtJoueur4.getWidth() / 2, 13 * getHeight() / 24 - txtJoueur4.getHeight() / 2);
        btnPasserTour.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        btnPasserTour.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() - btnPasserTour.getHeight() - (int) (getWidth() * RATIO_INTERFACE) / 15);
        lblInterfaceNom.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblInterfaceNom.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, (int) (getWidth() * RATIO_INTERFACE) / 15);
        lblVie.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblVie.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, 2 * (int) (getWidth() * RATIO_INTERFACE) / 15 + lblVie.getHeight());
        lblEssence.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblEssence.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, 3 * (int) (getWidth() * RATIO_INTERFACE) / 15 + 2 * lblEssence.getHeight());
        lblAmmo.setSize((int) (getWidth() * RATIO_INTERFACE) - 2 * (int) (getWidth() * RATIO_INTERFACE) / 15, getHeight() / 12);
        lblAmmo.setLocation((int) (getWidth() * RATIO_INTERFACE) / 15, 4 * (int) (getWidth() * RATIO_INTERFACE) / 15 + 3 * lblAmmo.getHeight());
        lblTete.setSize(lblTete.getFontMetrics(lblTete.getFont()).stringWidth(lblTete.getText()), lblTete.getFontMetrics(lblTete.getFont()).getHeight());
        lblTete.setLocation(getWidth() / 2 - lblTete.getWidth() / 2, getHeight() / 6 - lblTete.getHeight() / 2);
        lblOptionsViesTanks.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsViesTanks.setLocation(getWidth() / 2 - lblOptionsViesTanks.getWidth(), 6 * getHeight() / 24 - lblOptionsViesTanks.getHeight() / 2);
        lblOptionsFuelTanks.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsFuelTanks.setLocation(getWidth() / 2 - lblOptionsFuelTanks.getWidth(), 8 * getHeight() / 24 - lblOptionsFuelTanks.getHeight() / 2);
        lblOptionsAmmoTanks.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsAmmoTanks.setLocation(getWidth() / 2 - lblOptionsAmmoTanks.getWidth(), 10 * getHeight() / 24 - lblOptionsAmmoTanks.getHeight() / 2);
        lblOptionsDureeTour.setSize(2 * getWidth() / 9, getHeight() / 16);
        lblOptionsDureeTour.setLocation(getWidth() / 2 - lblOptionsDureeTour.getWidth(), 12 * getHeight() / 24 - lblOptionsDureeTour.getHeight() / 2);
        lblOptionsFrequenceFormes.setSize(2 * getWidth() / 8, getHeight() / 16);
        lblOptionsFrequenceFormes.setLocation(getWidth() / 2 - lblOptionsFrequenceFormes.getWidth(), 14 * getHeight() / 24 - lblOptionsFrequenceFormes.getHeight() / 2);
        cmbCouleurTank1.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank1.setLocation(txtJoueur1.getX() - cmbCouleurTank1.getWidth() - 10, 7 * getHeight() / 24 - cmbCouleurTank1.getHeight() / 2);
        cmbCouleurTank2.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank2.setLocation(txtJoueur2.getX() - cmbCouleurTank2.getWidth() - 10, 9 * getHeight() / 24 - cmbCouleurTank2.getHeight() / 2);
        cmbCouleurTank3.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank3.setLocation(txtJoueur3.getX() - cmbCouleurTank3.getWidth() - 10, 11 * getHeight() / 24 - cmbCouleurTank3.getHeight() / 2);
        cmbCouleurTank4.setSize(getWidth() / 6, getHeight() / 16);
        cmbCouleurTank4.setLocation(txtJoueur4.getX() - cmbCouleurTank4.getWidth() - 10, 13 * getHeight() / 24 - cmbCouleurTank4.getHeight() / 2);
        cmbPowerUp1.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp1.setLocation(txtJoueur1.getX() + txtJoueur1.getWidth() + 10, 7 * getHeight() / 24 - cmbPowerUp1.getHeight() / 2);
        cmbPowerUp2.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp2.setLocation(txtJoueur2.getX() + txtJoueur2.getWidth() + 10, 9 * getHeight() / 24 - cmbPowerUp2.getHeight() / 2);
        cmbPowerUp3.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp3.setLocation(txtJoueur3.getX() + txtJoueur3.getWidth() + 10, 11 * getHeight() / 24 - cmbPowerUp3.getHeight() / 2);
        cmbPowerUp4.setSize(getWidth() / 6, getHeight() / 16);
        cmbPowerUp4.setLocation(txtJoueur4.getX() + txtJoueur4.getWidth() + 10, 13 * getHeight() / 24 - cmbPowerUp4.getHeight() / 2);
        cmbResolution.setSize(getWidth() / 4, getHeight() / 16);
        cmbResolution.setLocation(getWidth() / 2 - cmbResolution.getWidth() / 2, getHeight() / 2 - cmbResolution.getHeight() / 2);
        cmbVieTanks.setSize(getWidth() / 9, getHeight() / 16);
        cmbVieTanks.setLocation(getWidth() / 2, 6 * getHeight() / 24 - cmbVieTanks.getHeight() / 2);
        cmbFuelTanks.setSize(getWidth() / 9, getHeight() / 16);
        cmbFuelTanks.setLocation(getWidth() / 2, 8 * getHeight() / 24 - cmbFuelTanks.getHeight() / 2);
        cmbAmmoTanks.setSize(getWidth() / 9, getHeight() / 16);
        cmbAmmoTanks.setLocation(getWidth() / 2, 10 * getHeight() / 24 - cmbAmmoTanks.getHeight() / 2);
        cmbDureeTours.setSize(getWidth() / 9, getHeight() / 16);
        cmbDureeTours.setLocation(getWidth() / 2, 12 * getHeight() / 24 - cmbDureeTours.getHeight() / 2);
        cmbFrequenceFormes.setSize(getWidth() / 9, getHeight() / 16);
        cmbFrequenceFormes.setLocation(getWidth() / 2, 14 * getHeight() / 24 - cmbFrequenceFormes.getHeight() / 2);

        btnNouvellePartie.setResolution(resolution);
        btnOptions.setResolution(resolution);
        btnQuitter.setResolution(resolution);
        btnQuitterOui.setResolution(resolution);
        btnRetourMenu.setResolution(resolution);
        btnRetourJeu.setResolution(resolution);
        btnNbJoueurs2.setResolution(resolution);
        btnNbJoueurs3.setResolution(resolution);
        btnNbJoueurs4.setResolution(resolution);
        btnConfirmerNoms.setResolution(resolution);
        btnConfirmerOptionsPartie.setResolution(resolution);
        btnPasserTour.setResolution(resolution);
        lblInterfaceNom.setResolution(resolution);
        lblVie.setResolution(resolution);
        lblEssence.setResolution(resolution);
        lblAmmo.setResolution(resolution);

        if (resolution == Resolution.R1920x1080) {
            imgFondInterface = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Fond_Interface_1080.png"));
            cmbPowerUp1.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp2.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp3.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp4.setRenderer(new PupListRenderer(iconesPUP));
        } else if (resolution == Resolution.R1280x1024) {
            imgFondInterface = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Fond_Interface_1024.png"));
            cmbPowerUp1.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp2.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp3.setRenderer(new PupListRenderer(iconesPUP));
            cmbPowerUp4.setRenderer(new PupListRenderer(iconesPUP));
        } else if (resolution == Resolution.R800x600) {
            imgFondInterface = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/Fond_Interface_600.png"));
            cmbPowerUp1.setRenderer(new PupListRenderer(iconesPUP600));
            cmbPowerUp2.setRenderer(new PupListRenderer(iconesPUP600));
            cmbPowerUp3.setRenderer(new PupListRenderer(iconesPUP600));
            cmbPowerUp4.setRenderer(new PupListRenderer(iconesPUP600));
        }
        monde.setLocationMondeX((int) (getWidth() * RATIO_INTERFACE));
        monde.setSize(getWidth() - monde.getLocationMondeX(), getHeight());
        monde.setLocation(monde.getLocationMondeX(), 0);
        monde.refresh(resolutionInitiale, resolution);
    }

    public void setupEtiquettesInterface() {
        if (statutJeu == StatutJeu.PARTIE_EN_COURS) {
            try {
                lblVie.setStatMax((int) cmbVieTanks.getSelectedItem());
                lblEssence.setStatMax((int) cmbFuelTanks.getSelectedItem());
                lblAmmo.setStatMax((int) cmbAmmoTanks.getSelectedItem());
                lblVie.setRatioRemplissage(monde.getTanks().get(monde.getTour()).hP);
                lblEssence.setRatioRemplissage(monde.getTanks().get(monde.getTour()).fuel);
                lblAmmo.setRatioRemplissage(monde.getTanks().get(monde.getTour()).projectilesRestants);
            } catch (Exception e) {
            }
        }
    }

    public JComboBox<PowerUp> getCmbPowerUp1() {
        return cmbPowerUp1;
    }

    public JComboBox<PowerUp> getCmbPowerUp2() {
        return cmbPowerUp2;
    }

    public JComboBox<PowerUp> getCmbPowerUp3() {
        return cmbPowerUp3;
    }

    public JComboBox<PowerUp> getCmbPowerUp4() {
        return cmbPowerUp4;
    }

    public JComboBox<CouleurTank> getCmbCouleurTank1() {
        return cmbCouleurTank1;
    }

    public JComboBox<CouleurTank> getCmbCouleurTank2() {
        return cmbCouleurTank2;
    }

    public JComboBox<CouleurTank> getCmbCouleurTank3() {
        return cmbCouleurTank3;
    }

    public JComboBox<CouleurTank> getCmbCouleurTank4() {
        return cmbCouleurTank4;
    }
    
    public void setNomJoueurActif(int tour) {
        if (tour == 0) {
            lblInterfaceNom.setText(txtJoueur1.getText());
        } else if (tour == 1) {
            lblInterfaceNom.setText(txtJoueur2.getText());
        } else if (tour == 2) {
            lblInterfaceNom.setText(txtJoueur3.getText());
        } else if (tour == 3) {
            lblInterfaceNom.setText(txtJoueur4.getText());
        }
    }
}